package quoridor;


public class QuoridorCoordinate implements Coordinate {
	private int column;
	private int row;
	
	/**
	 * Coordinate constructor
	 * @param row index of the sqaure
	 * @param column index of the square
	 */
	public QuoridorCoordinate(int row, int column) {
		this.row = row;
		this.column = column;	
	}
	
	public QuoridorCoordinate(int row, char column) {
		this.row = row;
		this.column = Character.getNumericValue(column) - Character.getNumericValue('a') + 1;		
	}
	
	private boolean isValidIndex(int index) {
		return index > 0 || index < 9; 
	}
	
	public boolean isValidCoordinate() {
		return isValidIndex(row) && isValidIndex(column);
	}
	
	/**
	 * returns the column index of this coordinate
	 */
	public int getColumn() {
		return column;
	}

	/**
	 * returns the row index of this coordinate
	 */
	public int getRow() {
		return row;
	}

	@Override
	public boolean isAdjacent(Coordinate otherCoord) {
		int otherRow = otherCoord.getRow();
		int otherCol = otherCoord.getColumn();
		boolean isAdjacent = false;
		
		if (otherRow - row <= 1 && otherRow - row >= -1) {
			isAdjacent = true;
		}
		
		if (otherCol - column <= 1 && otherCol - column >= -1) {
			isAdjacent = true;
		}
		return isAdjacent;
	}

}
